package day03;

import java.nio.charset.StandardCharsets;

public class Demo02 {
    public static void main(String[] args) {
        /*
         * 使用Unicode扩展部分符号
         */
        String str = "今天心情\uD83D\uDE1D";
        System.out.println(str);
        /*
         * 测试unicode转UTF-8编码
         */
        //     单字节 双字节 三字节 四字节
        String s = "Javaλ表达式\uD83D\uDE1D";
        System.out.println(s);
        //将Unicode字符串转换为UTF-8编码
        byte[] bytes = s.getBytes(StandardCharsets.UTF_8);
        System.out.println(bytes.length); //19
        for(byte b: bytes){
            System.out.println(Integer.toBinaryString(b & 0xff));
        }
        //将UTF-8字节解码为Java字符串(Unicode)
        String ss = new String(bytes, StandardCharsets.UTF_8);
        System.out.println(ss);
    }
}
